<template>
  <el-popover
    ref="popover"
    placement="left"
    width="300"
    @show="setData"
  >
    <el-form v-model="renovateForm">
      <el-form-item label="整修班长:">
        <el-select v-model="renovateForm.technicianID" placeholder="请选择班长">
          <el-option v-for="user in allTechnician" :key="user.userId" :label="user.userName" :value="user.userId" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-input
          v-model="renovateForm.remarks"
          type="textarea"
          autosize
          placeholder="备注信息"
        />
      </el-form-item>
      <el-row type="flex" justify="end">
        <el-button size="mini" :disabled="!!data.renovateDetailID" type="primary" :loading="loading" round @click="submit">保 存</el-button>
      </el-row>
    </el-form>
    <el-button slot="reference" :disabled="!!data.renovateDetailID" :type="getColor()" :icon="getIcon()" circle />
  </el-popover>
</template>

<script>
import { addRenovateDetail } from '@/api/dailyInspection'
import { getAllUser } from '@/api/user'
import { mapGetters } from 'vuex'

export default {
  name: 'RenovateEnrollFrom',
  props: {
    data: {
      type: Object,
      default() {
        return {}
      }
    }
  },
  data() {
    return {
      renovateForm: {
        technicianID: '',
        remarks: '',
        damageNoticeID: ''
      },
      allTechnician: [],
      loading: false
    }
  },
  computed: {
    ...mapGetters([
      'departmentId'
    ])
  },
  methods: {
    submit() {
      this.loading = true
      addRenovateDetail(this.renovateForm).then(() => {
        this.$emit('submitSuccess')
        this.$message.success('保存成功')
        this.loading = false
      })
    },
    setData() {
      this.renovateForm = this.data
      if (this.allTechnician.length === 0) {
        getAllUser(this.departmentId).then(data => {
          this.allTechnician = data
        })
      }
    },
    getIcon() {
      if (this.data.renovateDetailID) {
        return 'el-icon-check'
      } else {
        return 'el-icon-edit'
      }
    },
    getColor() {
      if (this.data.renovateDetailID) {
        return 'success'
      } else {
        return 'primary'
      }
    }
  }
}
</script>

<style scoped>

</style>
